package com.laolu.icon.remote;

import com.sun.jna.Structure;
import com.sun.jna.platform.win32.WinNT.HANDLE;
import lombok.Getter;
import lombok.NonNull;
import lombok.extern.slf4j.Slf4j;


@Getter
@Slf4j
public class RemoteMemory_Struct<T extends Structure> extends RemoteMemoryOperation {
	
	/**
	 * 要写入远程进程的对象
	 */
	private final T DATA;
	
	public RemoteMemory_Struct(@NonNull T DATA, @NonNull HANDLE H_PROCESS) {
		super(DATA.size(), H_PROCESS);
		this.DATA = DATA;
	}
	
	@Override
	public boolean write() {
		DATA.write();
		return super.write(DATA.getPointer());
	}
	
	@Override
	public boolean read() {
		boolean result = super.read(DATA.getPointer());
		if (result) {
			DATA.read();
		}
		return result;
	}
}
